package com.zyl.pts.web.controller;

import com.zyl.pts.config.anno.SystemLog;
import com.zyl.pts.config.enums.CodeAndMessageEnum;
import com.zyl.pts.config.result.Result;
import com.zyl.pts.domain.dto.QRDTO.QRUpdateOrAddDTO;
import com.zyl.pts.service.QRService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.web.controller
 * @ClassName: QuarantineRegistrationController
 * @Description TODO(质检模块)
 * @Author 翟玉龙
 * @Date 2024/11/19-14:05
 */
@Tag(name = "质检管理", description = "质检管理")
@RestController
@RequestMapping("/quarantineRegistration")
@Validated
public class QRController {

    private final QRService qrService;

    public QRController(QRService qrService) {
        this.qrService = qrService;
    }

    /**
     * 分页并根据条件查询检疫记录接口
     * @param bQualified 检疫结果：合格或不合格
     * @param grMechanism 检疫机构，支持模糊查询
     * @param pageNum 当前页码
     * @param pageSize 每页显示条数
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "分页并根据条件查询检疫记录接口")
    @Operation(summary = "分页并根据条件查询检疫记录接口")
    @GetMapping("/query")
    public Result<?> queryQuarantineRegistration(
            @RequestParam(name = "bQualified", required = false) String bQualified,
            @RequestParam(name = "grMechanism", required = false) String grMechanism,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize
    ) {
        return Result.success(
                CodeAndMessageEnum.SUCCESS,
                qrService.queryQuarantineRegistration(bQualified, grMechanism, pageNum, pageSize)
        );
    }

    /**
     * 新增或更新检疫记录接口
     * @param qrUpdateOrAdd 检疫记录
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "新增或更新检疫记录接口")
    @Operation(summary = "新增或更新检疫记录接口")
    @PostMapping("/saveOrUpdate")
    public Result<?> addOrUpdateQuarantineRegistration(
            @RequestBody @Validated QRUpdateOrAddDTO qrUpdateOrAdd
    ) {
        return Result.success(
                qrService.addOrUpdate(qrUpdateOrAdd)
        );
    }

    /**
     * 根据检疫id删除检疫记录接口
     * @param grId 检疫id
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据检疫id删除检疫记录接口")
    @Operation(summary = "根据检疫id删除检疫记录接口")
    @DeleteMapping("/deleteById/{grId}")
    public Result<?> deleteQuarantineRegistration(
            @PathVariable("grId") Integer grId
    ) {
        return Result.success(
                qrService.deleteById(grId)
        );
    }

    /**
     * 批量删除检疫记录接口
     * @param ids 检疫id集合
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "批量删除检疫记录接口")
    @Operation(summary = "批量删除检疫记录接口")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteQuarantineRegistration(
            @RequestBody List<Integer> ids
    ) {
        return Result.success(
                qrService.deleteByIdAll(ids)
        );
    }
}
